package com.cskaoyan.service.impl;

import com.cskaoyan.bean.bo.*;
import com.cskaoyan.bean.pojo.MallSystem;
import com.cskaoyan.bean.pojo.MallSystemExample;
import com.cskaoyan.bean.vo.*;
import com.cskaoyan.mapper.MallSystemMapper;
import com.cskaoyan.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: zoey-zhu
 * @description:  配置管理: admin/config ---》 查询system表
 * @Date 14:40 2021/7/9
 */
@Service
public class ConfigServiceImpl implements ConfigService {

    @Autowired
    MallSystemMapper mallSystemMapper;

    /**
     * @Author: zoey-zhu
     * @description: 商场配置：查询system表
     * @Date 14:40 2021/7/9
     * url: http://182.92.235.201:8083/admin/config/mall
     */
    @Override
    public ConfigMallVO configMall() {

        List<ConfigKeyValueVO> configKeyValueVOList = mallSystemMapper.selectAllKeyValue();

        ConfigMallVO configMallVO = new ConfigMallVO();

        for (ConfigKeyValueVO config : configKeyValueVOList) {
            if ("cskaoyan_mall_mall_name".equals(config.getKey())){
                configMallVO.setCskaoyanmall_mall_name(config.getValue());
            }
            if ("cskaoyan_mall_mall_qq".equals(config.getKey())){
                configMallVO.setCskaoyanmall_mall_qq(config.getValue());
            }
            if ("cskaoyan_mall_mall_phone".equals(config.getKey())){
                configMallVO.setCskaoyanmall_mall_phone(config.getValue());
            }
            if ("cskaoyan_mall_mall_address".equals(config.getKey())){
                configMallVO.setCskaoyanmall_mall_address(config.getValue());
            }
        }

        return configMallVO;
    }

    /**
     * @Author: zoey-zhu
     * @description: 运费配置：查询system表
     * @Date 15:07 2021/7/9
     * url: http://182.92.235.201:8083/admin/config/express
     */
    @Override
    public ConfigExpressVO configExpress() {
        List<ConfigKeyValueVO> configKeyValueVOList = mallSystemMapper.selectAllKeyValue();

        ConfigExpressVO configExpressVO = new ConfigExpressVO();

        for (ConfigKeyValueVO config : configKeyValueVOList) {
            if ("cskaoyan_mall_express_freight_value".equals(config.getKey())){
                configExpressVO.setCskaoyanmall_express_freight_value(config.getValue());
            }
            if ("cskaoyan_mall_express_freight_min".equals(config.getKey())){
                configExpressVO.setCskaoyanmall_express_freight_min(config.getValue());
            }
        }

        return configExpressVO;
    }

    /**
     * @Author: zoey-zhu
     * @description: 订单配置：查询system表
     * @Date 15:07 2021/7/9
     * url: http://182.92.235.201:8083/admin/config/order
     */
    @Override
    public ConfigOrderVO configOrder() {
        List<ConfigKeyValueVO> configKeyValueVOList = mallSystemMapper.selectAllKeyValue();

        ConfigOrderVO configOrderVO = new ConfigOrderVO();

        for (ConfigKeyValueVO config : configKeyValueVOList) {
            if ("cskaoyan_mall_order_unconfirm".equals(config.getKey())){
                configOrderVO.setCskaoyanmall_order_unconfirm(config.getValue());
            }
            if ("cskaoyan_mall_order_unpaid".equals(config.getKey())){
                configOrderVO.setCskaoyanmall_order_unpaid(config.getValue());
            }
            if ("cskaoyan_mall_order_comment".equals(config.getKey())){
                configOrderVO.setCskaoyanmall_order_comment(config.getValue());
            }
        }

        return configOrderVO;
    }

    /**
     * @Author: zoey-zhu
     * @description: 小程序配置：查询system表
     * @Date 15:07 2021/7/9
     * url: http://182.92.235.201:8083/admin/config/wx
     */
    @Override
    public ConfigWxVO configWx() {
        List<ConfigKeyValueVO> configKeyValueVOList = mallSystemMapper.selectAllKeyValue();

        ConfigWxVO configWxVO = new ConfigWxVO();

        for (ConfigKeyValueVO config : configKeyValueVOList) {
            if ("cskaoyan_mall_wx_share".equals(config.getKey())){
                configWxVO.setCskaoyanmall_wx_share(config.getValue());
            }
            if ("cskaoyan_mall_wx_index_brand".equals(config.getKey())){
                configWxVO.setCskaoyanmall_wx_index_brand(config.getValue());
            }
            if ("cskaoyan_mall_wx_index_topic".equals(config.getKey())){
                configWxVO.setCskaoyanmall_wx_index_topic(config.getValue());
            }
            if ("cskaoyan_mall_wx_index_hot".equals(config.getKey())){
                configWxVO.setCskaoyanmall_wx_index_hot(config.getValue());
            }
            if ("cskaoyan_mall_wx_catlog_goods".equals(config.getKey())){
                configWxVO.setCskaoyanmall_wx_catlog_goods(config.getValue());
            }
            if ("cskaoyan_mall_wx_catlog_list".equals(config.getKey())){
                configWxVO.setCskaoyanmall_wx_catlog_list(config.getValue());
            }
            if ("cskaoyan_mall_wx_index_new".equals(config.getKey())){
                configWxVO.setCskaoyanmall_wx_index_new(config.getValue());
            }
        }

        return configWxVO;
    }

    /**
     * @Author: zoey-zhu
     * @description: 商场配置：更新system表
     * @Date 19:59 2021/7/12
     * url: http://182.92.235.201:8083/admin/config/mall
     */
    @Override
    public int configMallUpdate(ConfigMallBO configMallBO) {

        String cskaoyan_mall_mall_name = "cskaoyan_mall_mall_name";
        ConfigKeyValueBO bo1 = new ConfigKeyValueBO(cskaoyan_mall_mall_name, configMallBO.getCskaoyanmall_mall_name());
        String cskaoyan_mall_mall_qq = "cskaoyan_mall_mall_qq";
        ConfigKeyValueBO bo2 = new ConfigKeyValueBO(cskaoyan_mall_mall_qq, configMallBO.getCskaoyanmall_mall_qq());
        String cskaoyan_mall_mall_phone = "cskaoyan_mall_mall_phone";
        ConfigKeyValueBO bo3 = new ConfigKeyValueBO(cskaoyan_mall_mall_phone, configMallBO.getCskaoyanmall_mall_phone());
        String cskaoyan_mall_mall_address = "cskaoyan_mall_mall_address";
        ConfigKeyValueBO bo4 = new ConfigKeyValueBO(cskaoyan_mall_mall_address, configMallBO.getCskaoyanmall_mall_address());

        int update = 0;

        update += mallSystemMapper.updateValueByKey(bo1);
        update += mallSystemMapper.updateValueByKey(bo2);
        update += mallSystemMapper.updateValueByKey(bo3);
        update += mallSystemMapper.updateValueByKey(bo4);

        return update;
    }

    /**
     * @Author: zoey-zhu
     * @description: 运费配置：更新system表
     * @Date 20:02 2021/7/12
     * url: http://182.92.235.201:8083/admin/config/express
     */
    @Override
    public int configExpressUpdate(ConfigExpressBO configExpressBO) {


        String cskaoyan_mall_express_freight_value = "cskaoyan_mall_express_freight_value";
        ConfigKeyValueBO bo1 = new ConfigKeyValueBO(cskaoyan_mall_express_freight_value, configExpressBO.getCskaoyanmall_express_freight_value());
        String cskaoyan_mall_express_freight_min = "cskaoyan_mall_express_freight_min";
        ConfigKeyValueBO bo2 = new ConfigKeyValueBO(cskaoyan_mall_express_freight_min, configExpressBO.getCskaoyanmall_express_freight_min());

        int update = 0;

        update += mallSystemMapper.updateValueByKey(bo1);
        update += mallSystemMapper.updateValueByKey(bo2);

        return update;
    }

    /**
     * @Author: zoey-zhu
     * @description: 订单配置：更新system表
     * @Date 20:02 2021/7/12
     * url: http://182.92.235.201:8083/admin/config/order
     */
    @Override
    public int configOrderUpdate(ConfigOrderBO configOrderBO) {

        String cskaoyan_mall_order_unconfirm = "cskaoyan_mall_order_unconfirm";
        ConfigKeyValueBO bo1 = new ConfigKeyValueBO(cskaoyan_mall_order_unconfirm, configOrderBO.getCskaoyanmall_order_unconfirm());
        String cskaoyan_mall_order_unpaid = "cskaoyan_mall_order_unpaid";
        ConfigKeyValueBO bo2 = new ConfigKeyValueBO(cskaoyan_mall_order_unpaid, configOrderBO.getCskaoyanmall_order_unpaid());
        String cskaoyan_mall_order_comment = "cskaoyan_mall_order_comment";
        ConfigKeyValueBO bo3 = new ConfigKeyValueBO(cskaoyan_mall_order_comment, configOrderBO.getCskaoyanmall_order_comment());

        int update = 0;

        update += mallSystemMapper.updateValueByKey(bo1);
        update += mallSystemMapper.updateValueByKey(bo2);
        update += mallSystemMapper.updateValueByKey(bo3);

        return update;
    }

    /**
     * @Author: zoey-zhu
     * @description: 小程序配置：更新system表
     * @Date 20:02 2021/7/12
     * url: http://182.92.235.201:8083/admin/config/wx
     */
    @Override
    public int configWxUpdate(ConfigWxBO configWxBO) {

        ConfigKeyValueBO bo1 = new ConfigKeyValueBO("cskaoyan_mall_wx_share", configWxBO.getCskaoyanmall_wx_share());
        ConfigKeyValueBO bo2 = new ConfigKeyValueBO("cskaoyan_mall_wx_index_brand", configWxBO.getCskaoyanmall_wx_index_brand());
        ConfigKeyValueBO bo3 = new ConfigKeyValueBO("cskaoyan_mall_wx_index_topic", configWxBO.getCskaoyanmall_wx_index_topic());
        ConfigKeyValueBO bo4 = new ConfigKeyValueBO("cskaoyan_mall_wx_index_hot", configWxBO.getCskaoyanmall_wx_index_hot());
        ConfigKeyValueBO bo5 = new ConfigKeyValueBO("cskaoyan_mall_wx_catlog_goods", configWxBO.getCskaoyanmall_wx_catlog_goods());
        ConfigKeyValueBO bo6 = new ConfigKeyValueBO("cskaoyan_mall_wx_catlog_list", configWxBO.getCskaoyanmall_wx_catlog_list());
        ConfigKeyValueBO bo7 = new ConfigKeyValueBO("cskaoyan_mall_wx_index_new", configWxBO.getCskaoyanmall_wx_index_new());

        int update = 0;

        update += mallSystemMapper.updateValueByKey(bo1);
        update += mallSystemMapper.updateValueByKey(bo2);
        update += mallSystemMapper.updateValueByKey(bo3);
        update += mallSystemMapper.updateValueByKey(bo4);
        update += mallSystemMapper.updateValueByKey(bo5);
        update += mallSystemMapper.updateValueByKey(bo6);
        update += mallSystemMapper.updateValueByKey(bo7);

        return update;
    }

}
